package chapter13_threadSafe;

import java.util.Vector;

public class P13_2 {
    public static void main(String[] args) {
        p1();
    }

    private static void p1(){
        Vector<Integer> vector = new Vector<>();
        while (true){
            for (int i = 0; i < 100; i++) {
                vector.add(i);
            }
            Thread thread = new Thread(()->{
                for (int i = 0; i < vector.size(); i++) {
                    vector.remove(i);
                }
            });
            Thread thread1 = new Thread(()->{
                for (int i = 0; i < vector.size(); i++) {
                    System.out.println(vector.get(i));
                }
            });
            thread.start();
            thread1.start();
            while (Thread.activeCount() > 20){}
        }
    }
}
